import { createRouter, createWebHistory } from 'vue-router';
import routes from './routes';
import { App } from 'vue';

import userStore from '@/store/user-store';
import autoLoad from './autoload';
import guard from './guard';

const router = createRouter({
  history: createWebHistory(),
  routes: [...routes]
});

export async function setupRouter(app: App) {
  // 先获取用户的权限，再进行权限路由的加载
  const user = userStore();
  await user.getUserInfo();

  autoLoad(router);
  guard(router);
  app.use(router);
}

export default router;
